package com.gxa.modules.pc.fee.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.modules.app.hospitalization.persional.mapper.PatientMapper;
import com.gxa.modules.model.dto.DetailInfoDto2;
import com.gxa.modules.model.dto.InpatientConsumptionRecordsDto;
import com.gxa.modules.model.dto.MedicineDto;
import com.gxa.modules.model.dto.RefundSearchDto;
import com.gxa.modules.model.entity.fee.InOrderDetail;
import com.gxa.modules.model.entity.fee.InpatientConsumptionRecords;
import com.gxa.modules.model.entity.fee.Patient;
import com.gxa.modules.pc.fee.mapper.InOrderDetailMapper;
import com.gxa.modules.pc.fee.mapper.InpatientConsumptionRecordsMapper;
import com.gxa.modules.pc.fee.mapper.InpatientDetailMapper;
import com.gxa.modules.pc.fee.mapper.MedicineCostDetailMapper;
import com.gxa.modules.pc.fee.service.InpatientConsumptionRecordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 住院消费记录表 服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:31:54
 */
@Service
@Slf4j
public class InpatientConsumptionRecordsServiceImpl extends ServiceImpl<InpatientConsumptionRecordsMapper, InpatientConsumptionRecords> implements InpatientConsumptionRecordsService {

    @Autowired
    private InpatientConsumptionRecordsMapper inpatientConsumptionRecordsMapper;

    @Autowired
    private PatientMapper patientMapper;

    @Autowired
    private InpatientDetailMapper inpatientDetailMapper;

    @Autowired
    private MedicineCostDetailMapper medicineCostDetailMapper;

    @Autowired
    private InOrderDetailMapper inOrderDetailMapper;

    @Override
    public PageUtils queryListSearch(RefundSearchDto refundSearchDto) {
        Integer pageSize = refundSearchDto.getPageSize();
        Integer pageNum1 = refundSearchDto.getPageNum();

        Integer pageNum2 = (pageNum1-1)*pageSize;
        log.info("---------{}--", pageNum2);
        refundSearchDto.setPageNum(pageNum2);
        List<InpatientConsumptionRecordsDto> inpatientConsumptionRecordsDtoList = this.inpatientConsumptionRecordsMapper.queryBySearch(refundSearchDto);
        Integer count = this.inpatientConsumptionRecordsMapper.count(refundSearchDto);
        PageUtils pageUtils = new PageUtils(inpatientConsumptionRecordsDtoList, count, pageSize, pageNum1);
        return pageUtils;
    }

    @Override
    public Map<String, Object> queryInfo(Integer patientId, Integer inInfoId, Integer inOrderId) {
        Map<String,Object> map = new HashMap<>();
        Patient patient = this.patientMapper.queryById(patientId);
        map.put("patient",patient);
        DetailInfoDto2 detailInfoDto = this.inpatientDetailMapper.queryBySerch(inInfoId);
        map.put("detailInfoDto",detailInfoDto);
        List<MedicineDto> medicineDtoList = this.medicineCostDetailMapper.queryById(inInfoId);
        map.put("medicineDtoList",medicineDtoList);
        InOrderDetail inOrderDetail = this.inOrderDetailMapper.queryById(inOrderId);
        map.put("inOrderDetail",inOrderDetail);

        return map;
    }

    @Override
    public List<InpatientConsumptionRecordsDto> queryList() {
        List<InpatientConsumptionRecordsDto> inpatientConsumptionRecordsDtoList = this.inpatientConsumptionRecordsMapper.queryList();
        return inpatientConsumptionRecordsDtoList;
    }
}
